package com.qch.rabbitmq.demo;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.net.URISyntaxException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

/**
 * @Author qch
 * @Date 2021/5/13
 */
public class Producer {
    public static void main(String[] args) throws Exception{
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setUri("amqp://root:123456@192.168.142.135:5672/%2f");
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("queue.wq",true,false,false,null);
        channel.exchangeDeclare("ex.wq",BuiltinExchangeType.DIRECT,true,false,null);
        channel.queueBind("queue.wq","ex.wq","key.wq");
        for (int i = 0; i < 15; i++) {
            channel.basicPublish("ex.wq","key.wq",null,("工作队列"+i).getBytes("utf-8"));
        }

        channel.close();
        connection.close();
    }
}
